package com.ssyc.student.adapter;

import android.content.Context;
import android.support.annotation.Nullable;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.ssyc.common.utils.MathUtil;
import com.ssyc.common.view.ZzHorizontalProgressBar;
import com.ssyc.student.R;
import com.ssyc.student.bean.AchievementRunningInfo;

import java.util.List;

/**
 * 学生端--成就--每周成就列表适配器
 * Created by Administrator on 2018/4/11 0011.
 */

public class StAchievementRunningAdapter extends BaseQuickAdapter<AchievementRunningInfo.Data1Bean, BaseViewHolder> {
    private Context context;

    public StAchievementRunningAdapter(Context context, int layoutResId, @Nullable List<AchievementRunningInfo.Data1Bean> data) {
        super(layoutResId, data);
        this.context = context;
    }

    @Override
    protected void convert(BaseViewHolder helper, AchievementRunningInfo.Data1Bean item) {
        //图标
        ImageView iv = helper.getView(R.id.iv);
        if ("初见成效".equals(item.getHonor())) {
            iv.setImageResource(R.drawable.st_cjcx);
        } else if ("初战告捷".equals(item.getHonor())) {
            iv.setImageResource(R.drawable.st_czgj);
        } else if ("持之以恒".equals(item.getHonor())) {
            iv.setImageResource(R.drawable.st_czyh);
        } else if ("势如破竹".equals(item.getHonor())) {
            iv.setImageResource(R.drawable.st_srpz);
        } else if ("终成大器".equals(item.getHonor())) {
            iv.setImageResource(R.drawable.st_zcdq);
        } else if ("战无不胜".equals(item.getHonor())) {
            iv.setImageResource(R.drawable.st_zwbs);
        } else if ("旗开得胜".equals(item.getHonor())) {
            iv.setImageResource(R.drawable.st_qkds);
        }


        //完成任务数量
        TextView tvNum = helper.getView(R.id.tv_num);
        tvNum.setText(item.getContent());

        //进度条
        ZzHorizontalProgressBar pb = helper.getView(R.id.pb);
        pb.setBgColor(context.getResources().getColor(R.color.st_pb_running_bg));
        pb.setProgressColor(context.getResources().getColor(R.color.st_pb_running_pb));

        //计算进度
        int curr = item.getCur_amount();
        int total = item.getAmount();
        pb.setProgress((int) (MathUtil.deciMal(curr, total) * 100));

        //显示进度的TextView
        TextView tvPbNum = helper.getView(R.id.tv_pb_num);
        tvPbNum.setText((int) (MathUtil.deciMal(curr, total) * 100)+"%");

        //奖励金币数
        TextView tvGold = helper.getView(R.id.tv_gold);
        tvGold.setText(item.getCoin() + "金币");

        //状态
        Button btState = helper.getView(R.id.bt_state);
    }
}
